home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / jpl_c.zip / FINT.C < prev    next >
Text File  |  1986-05-18  |  2KB  |  75 lines

  1. /* 1.0  06-27-85                        (fint.c)
  2.  ************************************************************************
  3.  *            Robert C. Tausworthe                *
  4.  *            Jet Propulsion Laboratory            *
  5.  *            Pasadena, CA 91009        1985        *
  6.  ************************************************************************/
  7.  
  8. #include "defs.h"
  9. #include "stdtyp.h"
  10.  
  11. /************************************************************************/
  12.     double
  13. fint(x)            /* return integer part of x as double        */
  14.  
  15. /*----------------------------------------------------------------------*/
  16. double x;
  17. {
  18.     int i, ex2, byte;
  19.     BITS bitmask;
  20.     TBITS *xp;
  21.     LOCAL TBITS mask[8] = 
  22.         {0, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe};
  23.  
  24.     xp = (char *) &x;
  25.  
  26. #ifdef ECOSOFT
  27.     ex2 = (((int) xp[0]) - 0x80);/* implied normalized bit, but sign is */
  28.     byte = ex2 / 8 + 1;    /*     in the normalized place        */
  29.     bitmask = mask[ex2 & 7];    /* i.e., % 8    */
  30. #endif
  31.  
  32. #ifdef AZTEC
  33.     ex2 = (((int) (xp[0] & 0x7f)) - 0x40); /* base 256    */
  34.     byte = 1 + ex2;
  35.     bitmask = 0;
  36. #endif
  37.  
  38. #ifdef CPM86
  39.     ex2 = (((int) (((xp[7] << 4) + (xp[6] >> 4)) & 0x7ff)) - 0x3fe + 3);
  40.     byte = 6 - ex2 / 8;    /* has implied normalized bit    */
  41.     bitmask = mask[ex2 & 7];
  42. #endif
  43.  
  44. #ifdef UNIVERSE
  45.     ex2 = (((int)(((*xp << 1) + (xp[1] &0x80 ? 1 : 0)) & 0xff)) - 0x80);
  46.     byte = 1 + ex2 / 8; /* has normalized bit, but extended exponent */
  47.     bitmask = mask[ex2 & 7];
  48. #endif
  49. /*\p*/
  50.  
  51. #ifdef SUN
  52.     ex2 = (int)(((*xp & 0x7f)<<4) + ((xp[1]>>4) & 0xf) - 0x3fe);
  53.     byte = (i = ex2 + 11) / 8;    /* i is location of dec. pt.    */ 
  54.     bitmask = mask[i & 7];
  55. #endif
  56.  
  57.     if (ex2 < 1)
  58.         return 0.0;
  59.  
  60. #ifdef CPM86
  61.     if (byte > -1)
  62.     {    xp[byte] &= bitmask;
  63.         for (i = --byte; i > -1; i--)
  64.             xp[i] = 0;
  65.     }
  66. #else
  67.     if (byte < 8)
  68.     {    xp[byte] &= bitmask;
  69.         for (i = ++byte; i < 8; i++)
  70.             xp[i] = 0;
  71.     }
  72. #endif
  73.     return x;
  74. }
  75.